﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SAM_Edu.entity;
using SAM_Edu.control;

namespace SAM_Edu.form
{
    public partial class frmUpdateUser : Form
    {
        static int uid;
        public frmUpdateUser(Accounts a, User u)
        {


            InitializeComponent();
            tbusername.Text = a.Username;
            tbpw.Text = a.Password;
            tbsecQN.Text = a.SecurityQuestion;
            tbSecANS.Text = a.SecurityAnswer;
            tbrfidno.Text = a.RfidNum;

            tbfullname.Text = u.FirstName;
            tbemail.Text = u.Email;
            tbcountrycode.Text = u.CountryCode.ToString();
            tbareacode.Text = u.AreaCode.ToString();
            tbmobileno.Text = u.MobileNumber.ToString();
            uid = u.UID;

        }

        public frmUpdateUser()
        {



        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {

            string username = tbusername.Text;
            string password = tbpw.Text;
            string securityQN = tbsecQN.Text;
            string securityAns = tbSecANS.Text;
            string rfidno = tbrfidno.Text;

            string fullname = tbfullname.Text;
            string email = tbemail.Text;
            int ccode = int.Parse(tbcountrycode.Text);
            int areacode = int.Parse(tbareacode.Text);
            int mobileno = int.Parse(tbmobileno.Text);
            bool status2 = UpdateUser.UpdateUserInformation(fullname, email, ccode, areacode, mobileno, uid);

            bool status = UpdateUser.UpdateAccountInformation(username, password, securityQN, securityAns, rfidno);
            if (status == status2 == true)
            {
                MessageBox.Show("Update success");
            }
            else
            {
                MessageBox.Show("Update Error");
            }
        }
    }
}
